<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-ps2ctrl-v4.h</h1>  </div>
</div>
<div class="contents">
<a href="mindsensors-ps2ctrl-v4_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*!@addtogroup mindsensors</span>
<a name="l00002"></a>00002 <span class="comment"> * @{</span>
<a name="l00003"></a>00003 <span class="comment"> * @defgroup PSP4 PSP-Nx V4</span>
<a name="l00004"></a>00004 <span class="comment"> * Playstation 2 Controller Sensor</span>
<a name="l00005"></a>00005 <span class="comment"> * @{</span>
<a name="l00006"></a>00006 <span class="comment"> */</span>
<a name="l00007"></a>00007 
<a name="l00008"></a>00008 <span class="comment">/*</span>
<a name="l00009"></a>00009 <span class="comment"> * $Id: mindsensors-ps2ctrl-v4.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="preprocessor">#ifndef __PSPV4_H__</span>
<a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#define __PSPV4_H__</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="comment">/** \file mindsensors-ps2ctrl-v4.h</span>
<a name="l00015"></a>00015 <span class="comment"> * \brief Playstation 2 Controller Sensor</span>
<a name="l00016"></a>00016 <span class="comment"> *</span>
<a name="l00017"></a>00017 <span class="comment"> * mindsensors-ps2ctrl-v4.h provides an API for the Mindsensors PS2 controller sensor</span>
<a name="l00018"></a>00018 <span class="comment"> * with referee signal receiver.</span>
<a name="l00019"></a>00019 <span class="comment"> *</span>
<a name="l00020"></a>00020 <span class="comment"> * Changelog:</span>
<a name="l00021"></a>00021 <span class="comment"> * - 0.1: Initial release</span>
<a name="l00022"></a>00022 <span class="comment"> *</span>
<a name="l00023"></a>00023 <span class="comment"> * Credits:</span>
<a name="l00024"></a>00024 <span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<a name="l00025"></a>00025 <span class="comment"> *</span>
<a name="l00026"></a>00026 <span class="comment"> * License: You may use this code as you wish, provided you give credit where its due.</span>
<a name="l00027"></a>00027 <span class="comment"> *</span>
<a name="l00028"></a>00028 <span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<a name="l00029"></a>00029 <span class="comment"></span>
<a name="l00030"></a>00030 <span class="comment"> * \author Xander Soldaat (xander_at_botbench.com)</span>
<a name="l00031"></a>00031 <span class="comment"> * \date 30 July 2012</span>
<a name="l00032"></a>00032 <span class="comment"> * \version 0.1</span>
<a name="l00033"></a>00033 <span class="comment"> * \example mindsensors-ps2ctrl-v4-test1.c</span>
<a name="l00034"></a>00034 <span class="comment"> * \example mindsensors-ps2ctrl-v4-test2.c</span>
<a name="l00035"></a>00035 <span class="comment"> */</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 <span class="preprocessor">#pragma systemFile</span>
<a name="l00038"></a>00038 <span class="preprocessor"></span>
<a name="l00039"></a>00039 <span class="preprocessor">#ifndef __COMMON_H__</span>
<a name="l00040"></a>00040 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="common_8h.html" title="Commonly used functions used by drivers.">common.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#endif</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span>
<a name="l00043"></a><a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">00043</a> <span class="preprocessor">#define PSPV4_I2C_ADDR              0x02    </span><span class="comment">/*!&lt; PSP-Nx V4 I2C device address */</span>
<a name="l00044"></a>00044 
<a name="l00045"></a><a class="code" href="group___p_s_p4.html#ga2561e7d51154392c5d6b13e3f26c358c">00045</a> <span class="preprocessor">#define PSPV4_REG_CMD               0x41    </span><span class="comment">/*!&lt; Command register */</span>
<a name="l00046"></a>00046 
<a name="l00047"></a><a class="code" href="group___p_s_p4.html#ga6dba8735b3b4c25f443e3e20b91ae783">00047</a> <span class="preprocessor">#define PSPV4_CMD_INITIALISE        0x49    </span><span class="comment">/*!&lt; Initialisation command */</span>
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="group___p_s_p4.html#ga6c1ca8fae4519c35773cd6dcb81d5c5f">00049</a> <span class="preprocessor">#define PSPV4_REG_BTN_SET_1         0x42    </span><span class="comment">/*!&lt; First button set register */</span>
<a name="l00050"></a><a class="code" href="group___p_s_p4.html#ga08a1939066d030afbfa438c231814fef">00050</a> <span class="preprocessor">#define PSPV4_REG_BTN_SET_2         0x43    </span><span class="comment">/*!&lt; Second button set register */</span>
<a name="l00051"></a><a class="code" href="group___p_s_p4.html#gab2326a8363464d917d5209bc5ee03584">00051</a> <span class="preprocessor">#define PSPV4_REG_JLEFT             0x44    </span><span class="comment">/*!&lt; Left joystick register */</span>
<a name="l00052"></a><a class="code" href="group___p_s_p4.html#ga6b84f66d60719b4ce8ef0ba6e3983054">00052</a> <span class="preprocessor">#define PSPV4_REG_JRIGHT            0x46    </span><span class="comment">/*!&lt; Right joystick register */</span>
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="group___p_s_p4.html#ga63d26bf2ba63de59617843b563b4ea81">00054</a> <span class="preprocessor">#define PSPV4_REG_PRES_JPAD_UP      0x4A    </span><span class="comment">/*!&lt; Joypad up button register */</span>
<a name="l00055"></a><a class="code" href="group___p_s_p4.html#ga45ea291279778daeda43f60f821abcfb">00055</a> <span class="preprocessor">#define PSPV4_REG_PRES_JPAD_RIGHT   0x4B    </span><span class="comment">/*!&lt; Joypad right button register */</span>
<a name="l00056"></a><a class="code" href="group___p_s_p4.html#gadd34ad310d8f8f9a754d95d9ece74da6">00056</a> <span class="preprocessor">#define PSPV4_REG_PRES_JPAD_DOWN    0x4C    </span><span class="comment">/*!&lt; Joypad down button register */</span>
<a name="l00057"></a><a class="code" href="group___p_s_p4.html#ga18ea4aeaf45bd17c6dec945bc27cb52c">00057</a> <span class="preprocessor">#define PSPV4_REG_PRES_JPAD_LEFT    0x4D    </span><span class="comment">/*!&lt; Joypad left button register */</span>
<a name="l00058"></a><a class="code" href="group___p_s_p4.html#ga326ea28d51e28f76fe1683eca96e8734">00058</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_L2       0x4E    </span><span class="comment">/*!&lt; L2 button register */</span>
<a name="l00059"></a><a class="code" href="group___p_s_p4.html#ga7dc8e9112e86b659b894081470efd468">00059</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_R2       0x4F    </span><span class="comment">/*!&lt; R2 button register */</span>
<a name="l00060"></a><a class="code" href="group___p_s_p4.html#ga48d5565cb50a9515a1434496b052e6dc">00060</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_L1       0x50    </span><span class="comment">/*!&lt; L1 button register */</span>
<a name="l00061"></a><a class="code" href="group___p_s_p4.html#ga3997715d96d088cc667288e03718c3d0">00061</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_R1       0x51    </span><span class="comment">/*!&lt; R1 button register */</span>
<a name="l00062"></a><a class="code" href="group___p_s_p4.html#ga40455f538f39ddb4b764882a25dad4f0">00062</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_TRIANGLE 0x52    </span><span class="comment">/*!&lt; Triangle button button register */</span>
<a name="l00063"></a><a class="code" href="group___p_s_p4.html#ga7a330e7592ca9eff3b6b6b456a54867b">00063</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_SQUARE   0x53    </span><span class="comment">/*!&lt; Square button register */</span>
<a name="l00064"></a><a class="code" href="group___p_s_p4.html#ga625c00b28fa05c30e9015fde53b043bb">00064</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_CIRCLE   0x54    </span><span class="comment">/*!&lt; Circle button register */</span>
<a name="l00065"></a><a class="code" href="group___p_s_p4.html#ga2d64bef67d5be4e68a4655fefec33b37">00065</a> <span class="preprocessor">#define PSPV4_REG_PRES_BTN_CROSS    0x55    </span><span class="comment">/*!&lt; Cross button register */</span>
<a name="l00066"></a>00066 
<a name="l00067"></a><a class="code" href="group___p_s_p4.html#ga7f939ee3aedc2dcef5dedd2b94bbd798">00067</a> <span class="preprocessor">#define PSPV4_REG_REF_SIGNAL_CODE   0x56    </span><span class="comment">/*!&lt; Referee Signal Code register */</span>
<a name="l00068"></a><a class="code" href="group___p_s_p4.html#gae24aafcbc51b15e7273a01785efc6358">00068</a> <span class="preprocessor">#define PSPV4_REG_REF_TX_TYPE       0x57    </span><span class="comment">/*!&lt; Referee Transmitter Type register */</span>
<a name="l00069"></a><a class="code" href="group___p_s_p4.html#ga3361e0ea1089feb9f617c6c44fa387ac">00069</a> <span class="preprocessor">#define PSPV4_REG_REF_SIGNAL_RAW    0x58    </span><span class="comment">/*!&lt; Referee Signal Raw Value register */</span>
<a name="l00070"></a><a class="code" href="group___p_s_p4.html#ga52039cab69434adceb1b78fd6d85141b">00070</a> <span class="preprocessor">#define PSPV4_REG_REF_SIGNAL_COUNT  0x5C    </span><span class="comment">/*!&lt; Referee Signal Count register */</span>
<a name="l00071"></a>00071 
<a name="l00072"></a><a class="code" href="group___p_s_p4.html#ga1c9bdc5f4a8306db3b4f080d2863806e">00072</a> <span class="preprocessor">#define PSPV4_SIGNAL_FAST_REWIND    0x32    </span><span class="comment">/*!&lt; Referee Signal &#39;fast rewind&#39; */</span>
<a name="l00073"></a><a class="code" href="group___p_s_p4.html#ga703a7ff57c6f2af1a0269a691f0da8fb">00073</a> <span class="preprocessor">#define PSPV4_SIGNAL_FAST_FORWARD   0x34    </span><span class="comment">/*!&lt; Referee Signal &#39;fast forward&#39; */</span>
<a name="l00074"></a><a class="code" href="group___p_s_p4.html#ga6b8c8bdf21d6e9e7c3c15397ecd49ac5">00074</a> <span class="preprocessor">#define PSPV4_SIGNAL_PLAY           0x35    </span><span class="comment">/*!&lt; Referee Signal &#39;play&#39; */</span>
<a name="l00075"></a><a class="code" href="group___p_s_p4.html#ga997ac1dfec9ccdd72f89b6f802232c04">00075</a> <span class="preprocessor">#define PSPV4_SIGNAL_STOP           0x36    </span><span class="comment">/*!&lt; Referee Signal &#39;stop&#39; */</span>
<a name="l00076"></a>00076 
<a name="l00077"></a><a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">00077</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>;     <span class="comment">/*!&lt; Array to hold I2C command data */</span>
<a name="l00078"></a><a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">00078</a> <a class="code" href="group__common.html#gaa172ef131853460e5b9f5c6db81d30f4">tByteArray</a> <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>;       <span class="comment">/*!&lt; Array to hold I2C reply data */</span>
<a name="l00079"></a>00079 
<a name="l00080"></a><a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">00080</a> <span class="keywordtype">bool</span> <a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">PSPV4initalised</a>[4] = {<span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>};
<a name="l00081"></a>00081 
<a name="l00082"></a><a class="code" href="structt_p_s_p.html">00082</a> <span class="keyword">typedef</span> <span class="keyword">struct</span>
<a name="l00083"></a>00083 {
<a name="l00084"></a>00084   <span class="comment">// computed button states</span>
<a name="l00085"></a><a class="code" href="structt_p_s_p.html#a0120b1db14fc663919f28c6ed6dd5d29">00085</a>   ubyte   <a class="code" href="structt_p_s_p.html#a0120b1db14fc663919f28c6ed6dd5d29">left1Btn</a>;           <span class="comment">/*!&lt; L1 button value */</span>
<a name="l00086"></a><a class="code" href="structt_p_s_p.html#a0fbcd00a7019c81108d0d863365effc2">00086</a>   ubyte   <a class="code" href="structt_p_s_p.html#a0fbcd00a7019c81108d0d863365effc2">left2Btn</a>;           <span class="comment">/*!&lt; L2 button value */</span>
<a name="l00087"></a><a class="code" href="structt_p_s_p.html#a4abb445ba2225148b73b99a6f0839d90">00087</a>   ubyte   <a class="code" href="structt_p_s_p.html#a4abb445ba2225148b73b99a6f0839d90">right1Btn</a>;          <span class="comment">/*!&lt; R1 button value */</span>
<a name="l00088"></a><a class="code" href="structt_p_s_p.html#a0e96ffb386f1d102a8ee7cfeb0273165">00088</a>   ubyte   <a class="code" href="structt_p_s_p.html#a0e96ffb386f1d102a8ee7cfeb0273165">rigth2Btn</a>;          <span class="comment">/*!&lt; R2 button value */</span>
<a name="l00089"></a><a class="code" href="structt_p_s_p.html#a6b92640ce55bf298642650802c8ebc1e">00089</a>   ubyte   <a class="code" href="structt_p_s_p.html#a6b92640ce55bf298642650802c8ebc1e">joypadLeft</a>;         <span class="comment">/*!&lt; Joypad left button value */</span>
<a name="l00090"></a><a class="code" href="structt_p_s_p.html#a0be01bf3bc76ad810e152e47c2da4fae">00090</a>   ubyte   <a class="code" href="structt_p_s_p.html#a0be01bf3bc76ad810e152e47c2da4fae">joypadDown</a>;         <span class="comment">/*!&lt; Joypad down button value */</span>
<a name="l00091"></a><a class="code" href="structt_p_s_p.html#af2104ef5c3802996564619a848afe853">00091</a>   ubyte   <a class="code" href="structt_p_s_p.html#af2104ef5c3802996564619a848afe853">joypadRight</a>;        <span class="comment">/*!&lt; Joypad right button value */</span>
<a name="l00092"></a><a class="code" href="structt_p_s_p.html#a870a98a6f4d5587b9757dd777594d065">00092</a>   ubyte   <a class="code" href="structt_p_s_p.html#a870a98a6f4d5587b9757dd777594d065">joypadUp</a>;           <span class="comment">/*!&lt; Joypad up button value */</span>
<a name="l00093"></a><a class="code" href="structt_p_s_p.html#ab28db7c3d877e2d9d7b5f2b898bedac5">00093</a>   ubyte   <a class="code" href="structt_p_s_p.html#ab28db7c3d877e2d9d7b5f2b898bedac5">triangleBtn</a>;        <span class="comment">/*!&lt; Triangle button button value */</span>
<a name="l00094"></a><a class="code" href="structt_p_s_p.html#a16b247c6baab766abeaefe6de45c8c39">00094</a>   ubyte   <a class="code" href="structt_p_s_p.html#a16b247c6baab766abeaefe6de45c8c39">squareBtn</a>;          <span class="comment">/*!&lt; Square button button value */</span>
<a name="l00095"></a><a class="code" href="structt_p_s_p.html#a13f356e1c57b3e4875ab8534b83988ab">00095</a>   ubyte   <a class="code" href="structt_p_s_p.html#a13f356e1c57b3e4875ab8534b83988ab">circleBtn</a>;          <span class="comment">/*!&lt; Circle button button value */</span>
<a name="l00096"></a><a class="code" href="structt_p_s_p.html#aa9e5c5e278454035e53036b390773d63">00096</a>   ubyte   <a class="code" href="structt_p_s_p.html#aa9e5c5e278454035e53036b390773d63">crossBtn</a>;           <span class="comment">/*!&lt; Cross button button value */</span>
<a name="l00097"></a><a class="code" href="structt_p_s_p.html#ac9c54ed7768261482b165be4a1efca1e">00097</a>   ubyte   <a class="code" href="structt_p_s_p.html#ac9c54ed7768261482b165be4a1efca1e">joystickLeftBtn</a>;    <span class="comment">/*!&lt; Left joystick button value */</span>
<a name="l00098"></a><a class="code" href="structt_p_s_p.html#a8c998b15fd2f04d93d2d571c112b2c19">00098</a>   ubyte   <a class="code" href="structt_p_s_p.html#a8c998b15fd2f04d93d2d571c112b2c19">joystickRightBtn</a>;   <span class="comment">/*!&lt; Right joystick button value */</span>
<a name="l00099"></a><a class="code" href="structt_p_s_p.html#a91014257757348dbc0e12f87fc7baddc">00099</a>   ubyte   <a class="code" href="structt_p_s_p.html#a91014257757348dbc0e12f87fc7baddc">selectBtn</a>;          <span class="comment">/*!&lt; Select button value */</span>
<a name="l00100"></a><a class="code" href="structt_p_s_p.html#ace3134ea1e457e9fb474a8b70aea6b24">00100</a>   ubyte   <a class="code" href="structt_p_s_p.html#ace3134ea1e457e9fb474a8b70aea6b24">startBtn</a>;           <span class="comment">/*!&lt; Start button value */</span>
<a name="l00101"></a><a class="code" href="structt_p_s_p.html#a4f0149c625b664e3ea802e50b16fb68f">00101</a>   <span class="keywordtype">int</span>   <a class="code" href="structt_p_s_p.html#a4f0149c625b664e3ea802e50b16fb68f">joystickLeft_x</a>;       <span class="comment">/*!&lt; Left joystick X value, scaled from 0 to 100 */</span>
<a name="l00102"></a><a class="code" href="structt_p_s_p.html#adf4baea875d5bf6ce4394e5ac05cd8b5">00102</a>   <span class="keywordtype">int</span>   <a class="code" href="structt_p_s_p.html#adf4baea875d5bf6ce4394e5ac05cd8b5">joystickLeft_y</a>;       <span class="comment">/*!&lt; Left joystick X value, scaled from 0 to 100 */</span>
<a name="l00103"></a><a class="code" href="structt_p_s_p.html#af61c8a3bb96e7385b72f78fa99560ae4">00103</a>   <span class="keywordtype">int</span>   <a class="code" href="structt_p_s_p.html#af61c8a3bb96e7385b72f78fa99560ae4">joystickRight_x</a>;      <span class="comment">/*!&lt; Left joystick X value, scaled from 0 to 100 */</span>
<a name="l00104"></a><a class="code" href="structt_p_s_p.html#a59602bcb0bfa6382a709f06f76a7aa8b">00104</a>   <span class="keywordtype">int</span>   <a class="code" href="structt_p_s_p.html#a59602bcb0bfa6382a709f06f76a7aa8b">joystickRight_y</a>;      <span class="comment">/*!&lt; Left joystick X value, scaled from 0 to 100 */</span>
<a name="l00105"></a>00105 } <a class="code" href="structt_p_s_p.html">tPSP</a>;
<a name="l00106"></a>00106 
<a name="l00107"></a><a class="code" href="group___p_s_p4.html#ga1c56a6059601b3554edc9adcc8736889">00107</a> <a class="code" href="structt_p_s_p.html">tPSP</a> <a class="code" href="group___p_s_p4.html#ga1c56a6059601b3554edc9adcc8736889">pspController</a>;
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 <span class="comment"></span>
<a name="l00110"></a>00110 <span class="comment">/**</span>
<a name="l00111"></a>00111 <span class="comment"> * Initialise the sensor.</span>
<a name="l00112"></a>00112 <span class="comment"> *</span>
<a name="l00113"></a>00113 <span class="comment"> * Note: This is an internal function and should not be used directly.</span>
<a name="l00114"></a>00114 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00115"></a>00115 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00116"></a>00116 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00117"></a>00117 <span class="comment"> */</span>
<a name="l00118"></a><a class="code" href="group___p_s_p4.html#gaf00b9346a95067b25dc993429c198642">00118</a> <span class="keywordtype">bool</span> <a class="code" href="group___p_s_p4.html#gaf00b9346a95067b25dc993429c198642">_PSPV4init</a>(tSensors link, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[0] = 3;                   <span class="comment">// Message size</span>
<a name="l00121"></a>00121   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[1] = address ;            <span class="comment">// I2C Address</span>
<a name="l00122"></a>00122   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[2] = 0x41;                <span class="comment">// Register address</span>
<a name="l00123"></a>00123   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[3] = <a class="code" href="group___p_s_p4.html#ga6dba8735b3b4c25f443e3e20b91ae783">PSPV4_CMD_INITIALISE</a>; <span class="comment">// Register address</span>
<a name="l00124"></a>00124 
<a name="l00125"></a>00125   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>))
<a name="l00126"></a>00126   {
<a name="l00127"></a>00127     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00128"></a>00128   }
<a name="l00129"></a>00129 
<a name="l00130"></a>00130         wait1Msec(100);                         <span class="comment">// wait for the dongle to initialize</span>
<a name="l00131"></a>00131         <a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">PSPV4initalised</a>[link] = <span class="keyword">true</span>;
<a name="l00132"></a>00132 
<a name="l00133"></a>00133         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 <span class="comment"></span>
<a name="l00137"></a>00137 <span class="comment">/**</span>
<a name="l00138"></a>00138 <span class="comment"> * Read a byte from the sensor</span>
<a name="l00139"></a>00139 <span class="comment"> *</span>
<a name="l00140"></a>00140 <span class="comment"> * Note: This is an internal function and should not be used directly.</span>
<a name="l00141"></a>00141 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00142"></a>00142 <span class="comment"> * @param reg the register to read</span>
<a name="l00143"></a>00143 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00144"></a>00144 <span class="comment"> * @return the ubyte value or 0 if an error occured</span>
<a name="l00145"></a>00145 <span class="comment"> */</span>
<a name="l00146"></a><a class="code" href="group___p_s_p4.html#ga408e5c340f57f7226ba1a5f3e8a7e7e7">00146</a> ubyte <a class="code" href="group___p_s_p4.html#ga408e5c340f57f7226ba1a5f3e8a7e7e7">_PSPV4readByte</a> (tSensors link, ubyte reg, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00147"></a>00147 {
<a name="l00148"></a>00148   <span class="comment">// Check if the controller has been initialised</span>
<a name="l00149"></a>00149   <span class="keywordflow">if</span> (!<a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">PSPV4initalised</a>[link])
<a name="l00150"></a>00150   {
<a name="l00151"></a>00151     <a class="code" href="group___p_s_p4.html#gaf00b9346a95067b25dc993429c198642">_PSPV4init</a>(link, address);
<a name="l00152"></a>00152   }
<a name="l00153"></a>00153 
<a name="l00154"></a>00154   memset(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>));
<a name="l00155"></a>00155 
<a name="l00156"></a>00156   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[0] = 2;                   <span class="comment">// Message size</span>
<a name="l00157"></a>00157   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[1] = address;  <span class="comment">// I2C Address</span>
<a name="l00158"></a>00158   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[2] = reg;            <span class="comment">// Register address</span>
<a name="l00159"></a>00159 
<a name="l00160"></a>00160   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>, 1))
<a name="l00161"></a>00161     <span class="keywordflow">return</span> 0;
<a name="l00162"></a>00162 
<a name="l00163"></a>00163   <span class="keywordflow">return</span> <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[0];
<a name="l00164"></a>00164 }
<a name="l00165"></a>00165 
<a name="l00166"></a>00166 <span class="comment"></span>
<a name="l00167"></a>00167 <span class="comment">/**</span>
<a name="l00168"></a>00168 <span class="comment"> * Read the button states.  Use PSPV4readButtonPressure() if you want</span>
<a name="l00169"></a>00169 <span class="comment"> * additional pressure values as well.</span>
<a name="l00170"></a>00170 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00171"></a>00171 <span class="comment"> * @param controllerState struct to hold all the button and joystick states and values</span>
<a name="l00172"></a>00172 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00173"></a>00173 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00174"></a>00174 <span class="comment"> */</span>
<a name="l00175"></a><a class="code" href="group___p_s_p4.html#gad139284e853e183891c69201568b465c">00175</a> <span class="keywordtype">bool</span> <a class="code" href="group___p_s_p4.html#gad139284e853e183891c69201568b465c">PSPV4readButtons</a>(tSensors link, <a class="code" href="structt_p_s_p.html">tPSP</a> &amp;controllerState, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177   ubyte b0;
<a name="l00178"></a>00178   ubyte b1;
<a name="l00179"></a>00179 
<a name="l00180"></a>00180   <span class="comment">// Check if the controller has been initialised</span>
<a name="l00181"></a>00181   <span class="keywordflow">if</span> (!<a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">PSPV4initalised</a>[link])
<a name="l00182"></a>00182   {
<a name="l00183"></a>00183     <a class="code" href="group___p_s_p4.html#gaf00b9346a95067b25dc993429c198642">_PSPV4init</a>(link, address);
<a name="l00184"></a>00184   }
<a name="l00185"></a>00185 
<a name="l00186"></a>00186   memset(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>));
<a name="l00187"></a>00187   memset(controllerState, 0, <span class="keyword">sizeof</span>(controllerState));
<a name="l00188"></a>00188 
<a name="l00189"></a>00189   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[0] = 2;                   <span class="comment">// Message size</span>
<a name="l00190"></a>00190   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[1] = address;             <span class="comment">// I2C Address</span>
<a name="l00191"></a>00191   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[2] = <a class="code" href="group___p_s_p4.html#ga6c1ca8fae4519c35773cd6dcb81d5c5f">PSPV4_REG_BTN_SET_1</a>;      <span class="comment">// Register address</span>
<a name="l00192"></a>00192 
<a name="l00193"></a>00193   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>, 6))
<a name="l00194"></a>00194     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00195"></a>00195 
<a name="l00196"></a>00196         b0 = ~<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[0];
<a name="l00197"></a>00197         b1 = ~<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[1];
<a name="l00198"></a>00198 
<a name="l00199"></a>00199         controllerState.<a class="code" href="structt_p_s_p.html#a91014257757348dbc0e12f87fc7baddc">selectBtn</a>         = (b0 &gt;&gt; 0) &amp; 0x01;
<a name="l00200"></a>00200         controllerState.<a class="code" href="structt_p_s_p.html#ac9c54ed7768261482b165be4a1efca1e">joystickLeftBtn</a>   = (b0 &gt;&gt; 1) &amp; 0x01;
<a name="l00201"></a>00201         controllerState.<a class="code" href="structt_p_s_p.html#a8c998b15fd2f04d93d2d571c112b2c19">joystickRightBtn</a>  = (b0 &gt;&gt; 2) &amp; 0x01;
<a name="l00202"></a>00202         controllerState.<a class="code" href="structt_p_s_p.html#ace3134ea1e457e9fb474a8b70aea6b24">startBtn</a>          = (b0 &gt;&gt; 3) &amp; 0x01;
<a name="l00203"></a>00203         controllerState.<a class="code" href="structt_p_s_p.html#a870a98a6f4d5587b9757dd777594d065">joypadUp</a>          = (b0 &gt;&gt; 4) &amp; 0x01;
<a name="l00204"></a>00204         controllerState.<a class="code" href="structt_p_s_p.html#af2104ef5c3802996564619a848afe853">joypadRight</a>       = (b0 &gt;&gt; 5) &amp; 0x01;
<a name="l00205"></a>00205         controllerState.<a class="code" href="structt_p_s_p.html#a0be01bf3bc76ad810e152e47c2da4fae">joypadDown</a>        = (b0 &gt;&gt; 6) &amp; 0x01;
<a name="l00206"></a>00206         controllerState.<a class="code" href="structt_p_s_p.html#a6b92640ce55bf298642650802c8ebc1e">joypadLeft</a>        = (b0 &gt;&gt; 7) &amp; 0x01;
<a name="l00207"></a>00207 
<a name="l00208"></a>00208         controllerState.<a class="code" href="structt_p_s_p.html#a0fbcd00a7019c81108d0d863365effc2">left2Btn</a>          = (b1 &gt;&gt; 0) &amp; 0x01;
<a name="l00209"></a>00209         controllerState.<a class="code" href="structt_p_s_p.html#a0e96ffb386f1d102a8ee7cfeb0273165">rigth2Btn</a>         = (b1 &gt;&gt; 1) &amp; 0x01;
<a name="l00210"></a>00210         controllerState.<a class="code" href="structt_p_s_p.html#a0120b1db14fc663919f28c6ed6dd5d29">left1Btn</a>          = (b1 &gt;&gt; 2) &amp; 0x01;
<a name="l00211"></a>00211         controllerState.<a class="code" href="structt_p_s_p.html#a4abb445ba2225148b73b99a6f0839d90">right1Btn</a>         = (b1 &gt;&gt; 3) &amp; 0x01;
<a name="l00212"></a>00212         controllerState.<a class="code" href="structt_p_s_p.html#ab28db7c3d877e2d9d7b5f2b898bedac5">triangleBtn</a>       = (b1 &gt;&gt; 4) &amp; 0x01;
<a name="l00213"></a>00213         controllerState.<a class="code" href="structt_p_s_p.html#a13f356e1c57b3e4875ab8534b83988ab">circleBtn</a>         = (b1 &gt;&gt; 5) &amp; 0x01;
<a name="l00214"></a>00214         controllerState.<a class="code" href="structt_p_s_p.html#aa9e5c5e278454035e53036b390773d63">crossBtn</a>          = (b1 &gt;&gt; 6) &amp; 0x01;
<a name="l00215"></a>00215         controllerState.<a class="code" href="structt_p_s_p.html#a16b247c6baab766abeaefe6de45c8c39">squareBtn</a>         = (b1 &gt;&gt; 7) &amp; 0x01;
<a name="l00216"></a>00216 
<a name="l00217"></a>00217         controllerState.<a class="code" href="structt_p_s_p.html#a4f0149c625b664e3ea802e50b16fb68f">joystickLeft_x</a>    = (((long)<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[2] - 128) * 100)/128;
<a name="l00218"></a>00218         controllerState.<a class="code" href="structt_p_s_p.html#adf4baea875d5bf6ce4394e5ac05cd8b5">joystickLeft_y</a>    = (((long)<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[3] - 128) * 100)/128;
<a name="l00219"></a>00219         controllerState.<a class="code" href="structt_p_s_p.html#af61c8a3bb96e7385b72f78fa99560ae4">joystickRight_x</a>   = (((long)<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[4] - 128) * 100)/128;
<a name="l00220"></a>00220         controllerState.<a class="code" href="structt_p_s_p.html#a59602bcb0bfa6382a709f06f76a7aa8b">joystickRight_y</a>   = (((long)<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[5] - 128) * 100)/128;
<a name="l00221"></a>00221 
<a name="l00222"></a>00222         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 <span class="comment"></span>
<a name="l00226"></a>00226 <span class="comment">/**</span>
<a name="l00227"></a>00227 <span class="comment"> * Read the button states with additional pressure values.  Use PSPV4readButtons() if you don&#39;t</span>
<a name="l00228"></a>00228 <span class="comment"> * care about how hard someone is pressing a button.</span>
<a name="l00229"></a>00229 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00230"></a>00230 <span class="comment"> * @param controllerState struct to hold all the button and joystick states and values</span>
<a name="l00231"></a>00231 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00232"></a>00232 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00233"></a>00233 <span class="comment"> */</span>
<a name="l00234"></a><a class="code" href="group___p_s_p4.html#ga476537b55149689ef213b9e6d57417e7">00234</a> <span class="keywordtype">bool</span> <a class="code" href="group___p_s_p4.html#ga476537b55149689ef213b9e6d57417e7">PSPV4readButtonPressure</a>(tSensors link, <a class="code" href="structt_p_s_p.html">tPSP</a> &amp;controllerState,  ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00235"></a>00235 {
<a name="l00236"></a>00236   <span class="comment">// Check if the controller has been initialised</span>
<a name="l00237"></a>00237   <span class="keywordflow">if</span> (!<a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">PSPV4initalised</a>[link])
<a name="l00238"></a>00238   {
<a name="l00239"></a>00239     <a class="code" href="group___p_s_p4.html#gaf00b9346a95067b25dc993429c198642">_PSPV4init</a>(link, address);
<a name="l00240"></a>00240   }
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   <span class="keywordflow">if</span> (!<a class="code" href="group___p_s_p4.html#gad139284e853e183891c69201568b465c">PSPV4readButtons</a>(link, controllerState, address))
<a name="l00243"></a>00243   {
<a name="l00244"></a>00244     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00245"></a>00245   }
<a name="l00246"></a>00246 
<a name="l00247"></a>00247   memset(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>));
<a name="l00248"></a>00248   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[0] = 2;                   <span class="comment">// Message size</span>
<a name="l00249"></a>00249   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[1] = address;  <span class="comment">// I2C Address</span>
<a name="l00250"></a>00250   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[2] = <a class="code" href="group___p_s_p4.html#ga63d26bf2ba63de59617843b563b4ea81">PSPV4_REG_PRES_JPAD_UP</a>;            <span class="comment">// Register address</span>
<a name="l00251"></a>00251 
<a name="l00252"></a>00252   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>, 12))
<a name="l00253"></a>00253     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00254"></a>00254 
<a name="l00255"></a>00255         controllerState.<a class="code" href="structt_p_s_p.html#a870a98a6f4d5587b9757dd777594d065">joypadUp</a>          = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[0]  * 100) / 255;
<a name="l00256"></a>00256   controllerState.<a class="code" href="structt_p_s_p.html#af2104ef5c3802996564619a848afe853">joypadRight</a>       = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[1]  * 100) / 255;
<a name="l00257"></a>00257   controllerState.<a class="code" href="structt_p_s_p.html#a0be01bf3bc76ad810e152e47c2da4fae">joypadDown</a>        = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[2]  * 100) / 255;
<a name="l00258"></a>00258   controllerState.<a class="code" href="structt_p_s_p.html#a6b92640ce55bf298642650802c8ebc1e">joypadLeft</a>        = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[3]  * 100) / 255;
<a name="l00259"></a>00259 
<a name="l00260"></a>00260   controllerState.<a class="code" href="structt_p_s_p.html#a0fbcd00a7019c81108d0d863365effc2">left2Btn</a>          = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[4]  * 100) / 255;
<a name="l00261"></a>00261   controllerState.<a class="code" href="structt_p_s_p.html#a0e96ffb386f1d102a8ee7cfeb0273165">rigth2Btn</a>         = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[5]  * 100) / 255;
<a name="l00262"></a>00262   controllerState.<a class="code" href="structt_p_s_p.html#a0120b1db14fc663919f28c6ed6dd5d29">left1Btn</a>          = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[6]  * 100) / 255;
<a name="l00263"></a>00263   controllerState.<a class="code" href="structt_p_s_p.html#a4abb445ba2225148b73b99a6f0839d90">right1Btn</a>         = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[7]  * 100) / 255;
<a name="l00264"></a>00264   controllerState.<a class="code" href="structt_p_s_p.html#ab28db7c3d877e2d9d7b5f2b898bedac5">triangleBtn</a>       = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[8]  * 100) / 255;
<a name="l00265"></a>00265   controllerState.<a class="code" href="structt_p_s_p.html#a13f356e1c57b3e4875ab8534b83988ab">circleBtn</a>         = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[9]  * 100) / 255;
<a name="l00266"></a>00266   controllerState.<a class="code" href="structt_p_s_p.html#aa9e5c5e278454035e53036b390773d63">crossBtn</a>          = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[10] * 100) / 255;
<a name="l00267"></a>00267   controllerState.<a class="code" href="structt_p_s_p.html#a16b247c6baab766abeaefe6de45c8c39">squareBtn</a>         = (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[11] * 100) / 255;
<a name="l00268"></a>00268 
<a name="l00269"></a>00269   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00270"></a>00270 }
<a name="l00271"></a>00271 <span class="comment"></span>
<a name="l00272"></a>00272 <span class="comment">/**</span>
<a name="l00273"></a>00273 <span class="comment"> * Read the last command sent by the referee.\n</span>
<a name="l00274"></a>00274 <span class="comment"> * Values can be:</span>
<a name="l00275"></a>00275 <span class="comment"> * - PSPV4_SIGNAL_FAST_REWIND</span>
<a name="l00276"></a>00276 <span class="comment"> * - PSPV4_SIGNAL_FAST_FORWARD</span>
<a name="l00277"></a>00277 <span class="comment"> * - PSPV4_SIGNAL_PLAY</span>
<a name="l00278"></a>00278 <span class="comment"> * - PSPV4_SIGNAL_STOP</span>
<a name="l00279"></a>00279 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00280"></a>00280 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00281"></a>00281 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00282"></a>00282 <span class="comment"> */</span>
<a name="l00283"></a><a class="code" href="group___p_s_p4.html#ga05068a35c691b19daae9ddbcd098da84">00283</a> byte <a class="code" href="group___p_s_p4.html#ga05068a35c691b19daae9ddbcd098da84">PSPV4readRefSignal</a>(tSensors link, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00284"></a>00284 {
<a name="l00285"></a>00285   <span class="keywordflow">return</span> <a class="code" href="group___p_s_p4.html#ga408e5c340f57f7226ba1a5f3e8a7e7e7">_PSPV4readByte</a>(link, <a class="code" href="group___p_s_p4.html#ga7f939ee3aedc2dcef5dedd2b94bbd798">PSPV4_REG_REF_SIGNAL_CODE</a>, address);
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 
<a name="l00288"></a>00288 <span class="comment"></span>
<a name="l00289"></a>00289 <span class="comment">/**</span>
<a name="l00290"></a>00290 <span class="comment"> * Signal Count - increments each time the sensor receives a signal from</span>
<a name="l00291"></a>00291 <span class="comment"> * the Referee (rolls over to 0 after 255)</span>
<a name="l00292"></a>00292 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00293"></a>00293 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00294"></a>00294 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00295"></a>00295 <span class="comment"> */</span>
<a name="l00296"></a><a class="code" href="group___p_s_p4.html#ga8ef579448f32b14702039578d25d0829">00296</a> byte <a class="code" href="group___p_s_p4.html#ga8ef579448f32b14702039578d25d0829">PSPV4readRefSignalCount</a>(tSensors link, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00297"></a>00297 {
<a name="l00298"></a>00298   <span class="keywordflow">return</span> <a class="code" href="group___p_s_p4.html#ga408e5c340f57f7226ba1a5f3e8a7e7e7">_PSPV4readByte</a>(link, <a class="code" href="group___p_s_p4.html#ga52039cab69434adceb1b78fd6d85141b">PSPV4_REG_REF_SIGNAL_COUNT</a>, address);
<a name="l00299"></a>00299 }
<a name="l00300"></a>00300 
<a name="l00301"></a>00301 <span class="comment"></span>
<a name="l00302"></a>00302 <span class="comment">/**</span>
<a name="l00303"></a>00303 <span class="comment"> * Fetch the transmitter type.  Can be used to differentiate between</span>
<a name="l00304"></a>00304 <span class="comment"> * various transmitter type (TV remote vs Referee Transmitter)</span>
<a name="l00305"></a>00305 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00306"></a>00306 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00307"></a>00307 <span class="comment"> * @return true if no error occured, false if it did</span>
<a name="l00308"></a>00308 <span class="comment"> */</span>
<a name="l00309"></a><a class="code" href="group___p_s_p4.html#gaddc1f44924b7c24e39e0e88485636ba3">00309</a> byte <a class="code" href="group___p_s_p4.html#gaddc1f44924b7c24e39e0e88485636ba3">PSPV4readRefTXType</a>(tSensors link, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00310"></a>00310 {
<a name="l00311"></a>00311   <span class="keywordflow">return</span> <a class="code" href="group___p_s_p4.html#ga408e5c340f57f7226ba1a5f3e8a7e7e7">_PSPV4readByte</a>(link, <a class="code" href="group___p_s_p4.html#gae24aafcbc51b15e7273a01785efc6358">PSPV4_REG_REF_TX_TYPE</a>, address);
<a name="l00312"></a>00312 }
<a name="l00313"></a>00313 
<a name="l00314"></a>00314 <span class="comment"></span>
<a name="l00315"></a>00315 <span class="comment">/**</span>
<a name="l00316"></a>00316 <span class="comment"> * Get the raw data from the receiver.  This is useful if custom commands</span>
<a name="l00317"></a>00317 <span class="comment"> * are to be implemented.  Simply map the returned value to a new command.</span>
<a name="l00318"></a>00318 <span class="comment"> * @param link the PSP sensor port</span>
<a name="l00319"></a>00319 <span class="comment"> * @param address I2C address, optional, defaults to PSPV4_I2C_ADDR</span>
<a name="l00320"></a>00320 <span class="comment"> * @return the raw value from the sensor</span>
<a name="l00321"></a>00321 <span class="comment"> */</span>
<a name="l00322"></a><a class="code" href="group___p_s_p4.html#ga808007b50ad236e78649a42d0c3b41ee">00322</a> <span class="keywordtype">long</span> <a class="code" href="group___p_s_p4.html#ga808007b50ad236e78649a42d0c3b41ee">PSPV4readRawRefTXValue</a>(tSensors link, ubyte address = <a class="code" href="group___p_s_p4.html#ga4b38b872559311663520214709e67be6">PSPV4_I2C_ADDR</a>)
<a name="l00323"></a>00323 {
<a name="l00324"></a>00324   <span class="comment">// Check if the controller has been initialised</span>
<a name="l00325"></a>00325   <span class="keywordflow">if</span> (!<a class="code" href="group___p_s_p4.html#ga1a31c7df4886601166b46381507bd661">PSPV4initalised</a>[link])
<a name="l00326"></a>00326   {
<a name="l00327"></a>00327     <a class="code" href="group___p_s_p4.html#gaf00b9346a95067b25dc993429c198642">_PSPV4init</a>(link, address);
<a name="l00328"></a>00328   }
<a name="l00329"></a>00329 
<a name="l00330"></a>00330   memset(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>));
<a name="l00331"></a>00331 
<a name="l00332"></a>00332   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[0] = 2;                        <span class="comment">// Message size</span>
<a name="l00333"></a>00333   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[1] = address;                  <span class="comment">// I2C Address</span>
<a name="l00334"></a>00334   <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>[2] = <a class="code" href="group___p_s_p4.html#ga3361e0ea1089feb9f617c6c44fa387ac">PSPV4_REG_REF_SIGNAL_RAW</a>; <span class="comment">// Register address</span>
<a name="l00335"></a>00335 
<a name="l00336"></a>00336   <span class="keywordflow">if</span> (!<a class="code" href="group__common.html#gad02e06f83b264ee6fc7df41eb4712080">writeI2C</a>(link, <a class="code" href="group___p_s_p4.html#ga888c1d6bce2491135586588332f5ee17">PSPV4_I2CRequest</a>, <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>, 4))
<a name="l00337"></a>00337     <span class="keywordflow">return</span> 0;
<a name="l00338"></a>00338 
<a name="l00339"></a>00339   <span class="keywordflow">return</span> <a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[0] + (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[1]&lt;&lt;8) + (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[2]&lt;&lt;16) + (<a class="code" href="group___p_s_p4.html#ga631e83a7c8d56968f1635f82fd62656b">PSPV4_I2CReply</a>[3]&lt;&lt;24);
<a name="l00340"></a>00340 }
<a name="l00341"></a>00341 
<a name="l00342"></a>00342 
<a name="l00343"></a>00343 
<a name="l00344"></a>00344 <span class="preprocessor">#endif // __PSPV4_H__</span>
<a name="l00345"></a>00345 <span class="preprocessor"></span>
<a name="l00346"></a>00346 <span class="comment">/*</span>
<a name="l00347"></a>00347 <span class="comment"> * $Id: mindsensors-ps2ctrl-v4.h 133 2013-03-10 15:15:38Z xander $</span>
<a name="l00348"></a>00348 <span class="comment"> */</span>
<a name="l00349"></a>00349 <span class="comment">/* @} */</span>
<a name="l00350"></a>00350 <span class="comment">/* @} */</span>
</pre></div></div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:43 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
